package com.utf999.qiangmanger.dao.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import com.utf999.qiangmanger.dao.AbstractRelationalDBDAO;
import com.utf999.qiangmanger.dao.iface.IOrderInfoCommodityDAO;
import com.utf999.qiangmanger.entity.orm.CommodityEntity;
import com.utf999.qiangmanger.entity.orm.OrderInfoCommodityEntity;
import com.utf999.qiangmanger.entity.orm.OrderInfoEntity;
import com.utf999.qiangmanger.exception.BizException;
import com.utf999.qiangmanger.exception.ResponseCode;

/**
 * @author yinwenjie
 */
@Component("OrderInfoCommodityDAOImpl")
public class OrderInfoCommodityDAOImpl extends AbstractRelationalDBDAO<OrderInfoCommodityEntity> implements IOrderInfoCommodityDAO {

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.AbstractRelationalDBDAO#getEntityClass()
	 */
	@Override
	protected Class<OrderInfoCommodityEntity> getEntityClass() {
		return OrderInfoCommodityEntity.class;
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.iface.IOrderInfoCommodityDAO#appendOrderInfoCommodity(java.lang.String, java.lang.String, java.lang.Integer)
	 */
	@Override
	public void appendOrderInfoCommodity(String orderinfoID, String commodityid, Integer commodityNumber) throws BizException {
		if(StringUtils.isEmpty(orderinfoID) || StringUtils.isEmpty(commodityid)
			|| commodityNumber == null) {
			throw new BizException("错误的参数信息，请检查", ResponseCode.E403);
		}
		
		OrderInfoCommodityEntity orderInfoCommodity = new OrderInfoCommodityEntity();
		//商品
		CommodityEntity commodify = new CommodityEntity();
		commodify.setUid(commodityid);
		orderInfoCommodity.setCommodify(commodify);
		orderInfoCommodity.setCommodifyNumber(commodityNumber);
		//工单信息
		OrderInfoEntity orderinfo = new OrderInfoEntity();
		orderinfo.setUid(orderinfoID);
		orderInfoCommodity.setOrderInfo(orderinfo);
		
		this.insert(orderInfoCommodity);
	}
}